package com.socket.serializableTest;

import com.socket.socketObjTest.Pet;

import java.io.*;
import java.net.Socket;

/**
 * PetClient--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-14 13:43
 **/
public class PetClient {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost", 9092);
        OutputStream os = socket.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(os);

        Pet pet = new Pet("pig2", "red");
        oos.writeObject(pet);

        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String repay;
        while ((repay = br.readLine()) != null) {
            System.out.println("我是宠物主人，宠物店回应："+repay);
        }

        br.close();
        is.close();
        oos.close();
        os.close();
        socket.close();
    }
}
